package com.example.myapplication4;


import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initview();
    }
    private  void initview(){
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        //RecyclerView 一开始必须给定列表样式，否则列表无法显示
                //   LinearLayoutManager 默认情况下是默认垂直的即vertical
               // LinearLayoutManager lim = new LinearLayoutManager(this);

                //垂直列表显示
               // lim.setOrientation(LinearLayoutManager.VERTICAL);

                //水平列表显示
                 // lim.setOrientation(LinearLayoutManager.HORIZONTAL);

                //网格排列
                //网格模式，默认垂直,给定默认为列
                //网格模式，设置水平后，原本的列数变为行数，水平滚动
                //是否反转reverseLayout
                GridLayoutManager glm = new GridLayoutManager(this,4,
                        GridLayoutManager.VERTICAL,false);
                recyclerView.setLayoutManager(glm);
        List<bean> data = new ArrayList<bean>();
        for (int i = 0; i < 20; i++) {
            bean b= new bean();
            b.setName("张三"+i);
            b.setImg(R.drawable.qie);
            data.add(b);

        }
        MyAdapter adapter = new MyAdapter(this);
        adapter.setData(data);
        recyclerView.setAdapter(adapter);
    }
}